|
|
|
| Incrementing a Global Variable 1. Run the sample project. 2. Open the VarExamples.frm form by clicking the Variables command button. 3. Click the Global command button a few times to see the value in the label next to it increment by 1 each time you click. 4. Try closing the form and then running it again to see whether the Global variable has retained its value. |  | Global variables will exist as long as the program is running. Variables declared with Public or Global are allocated on the heap, an area of memory thats allocated when the program starts and is discarded when the program ends. |
|
|
|
|
|
|
Local Variables Mask Public Variables |
|
|
|
|
|
|
|
|
If you name a Local variable the same name as a module-level or Public variable, the Local variable name will take precedence within that procedure. This means that you wont be able to access the Public variable from within the procedure. |
|
|
|
|
| Local Variables Override Public Variables 1. Stop the project from running. 2. Double-click the Override command button to display the following code: | | Private Sub cmdGlobalLocal_Click ()
' You would normally NOT name
' this variable this way
Dim gintCount As Integer
gintCount = 1
lblGlobalLocal.Caption = gintCount
End Sub |  | Notice how the gintCount variable is set to 1. This sets the value in the Local variable, gintCount, not in the Public variable. |
|
|
|